package de.koller.planet2D.frame.control;

import de.koller.planet2D.PNode;
import de.koller.planet2D.container.RenderObj;
import de.koller.planet2D.frame.IPositionClickNotifier;

public class ObjectChooser extends PNode {

	private final ObjSelector highlighter = new ObjSelector();
	
	@Override
	protected void init() {
		super.init();
		
		proot.previewFrame.renderPanel.clickNotifier.add( highlighter );
	}

	@Override
	protected void release() {
		super.release();
		
		proot.previewFrame.renderPanel.clickNotifier.remove( highlighter );
	}
	
	private class ObjSelector implements IPositionClickNotifier {

		@Override
		synchronized public void notifyPosition( double x, double y ) {
			double r = proot.previewFrame.pRenderNode.basicRenderer.lastUsedGripRadius();
			for( RenderObj o : proot.renderContainer.renderObjects )
				if( o.inSelect( x, y, r ) ) {
					proot.previewFrame.openObjectEdit( o );
					proot.updateThis();
					return;
				}
		}
		
	}
	
}
